<template>
  <div class="content-list" ref="contentList">
    <div class="left" @click="goToUserInside">
      <div class="imgbox">
        <img class="auto-img" :src="contentData.avatar" alt="" />
      </div>
      <div class="textbox">
        <div class="top">{{ contentData.content }}</div>
        <div class="bottom">
          帖子{{ contentData.counter.article_count }}&nbsp;&nbsp;浏览{{
            contentData.counter.view_count
          }}
        </div>
      </div>
    </div>
    <div class="follow-icon" @click="toFollow">
      {{ contentData.isFollow == true ? "已关注" : "关注" }}
    </div>
  </div>
</template>

<script>
export default {
  props: {
    contentData: {},
  },
  created() {
    this.$nextTick(() => {
      this.sentHeight();
    });
  },
  methods: {
    //关注
    toFollow() {
      let token = window.localStorage.getItem("token");
      if (!token) {
        this.$router.push({ name: "beforeLogin" });
      } else {
        this.$emit("followHandel");
      }
    },
    //向父组件传送总高度
    sentHeight() {
      this.$emit("getHeight", this.$refs.contentList.clientHeight);
    },
    //前往个人主页
    goToUserInside() {
      if (this.$route.name != "userInside") {
        this.$router.push({
          name: "userInside",
          params: { id: this.contentData.id },
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.content-list {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #ddd;
  padding-bottom: 10px;
  margin-bottom: 10px;
  &:last-child {
    border-bottom: none;
  }
  .left {
    display: flex;
    .imgbox {
      width: 45px;
      height: 45px;
      border-radius: 10px;
      overflow: hidden;
      margin-right: 10px;
    }
    .textbox {
      padding-top: 5px;
      .top {
        width: 200px;
        height: 16px;
        line-height: 16px;
        font-size: 15px;
        margin: 0 0 5px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .bottom {
        color: #666;
      }
    }
  }
  .follow-icon {
    width: 50px;
    height: 25px;
    background-color: rgb(253, 217, 58);
    border-radius: 999px;
    text-align: center;
    line-height: 25px;
    font-weight: 600;
  }
}
</style>